package com.sanpu.kxe.business.main.view;

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.base.BaseTitleActivity;
import com.sanpu.kxe.business.main.adapter.PushMaterialAdapter;
import com.sanpu.kxe.business.main.bean.PushMaterialOutput;
import com.sanpu.kxe.business.main.contract.PushMaterialContract;
import com.sanpu.kxe.business.main.presenter.PushMaterialPresenter;
import com.sanpu.kxe.business.main.provider.MainOpenProvider;
import com.sanpu.kxe.common.view.NoScrollGridView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

/**
 * Description：地推物料
 * Created by 薛勇军 on 2018/8/20.
 */

public class PushMaterialActivity extends BaseTitleActivity implements PushMaterialContract.View{

    @Bind(R.id.materialGv)
    NoScrollGridView materialGv;

    private PushMaterialAdapter materialAdapter;

    private PushMaterialContract.Presenter mPresenter;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_push_material;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setTitle("地推物料");
        materialAdapter = new PushMaterialAdapter(mContext, new ArrayList<PushMaterialOutput>());
        materialGv.setAdapter(materialAdapter);

        mPresenter = new PushMaterialPresenter(this);
        mPresenter.getMaterialList();
    }

    @Override
    protected void setListener() {
        super.setListener();
        materialGv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                PushMaterialOutput retDatBean = ((PushMaterialAdapter)parent.getAdapter()).getItem(position);
                if (retDatBean != null) {
                    MainOpenProvider.getInstance().openPushListActivity(mContext,
                            retDatBean.getName(), retDatBean.getType());
                }
            }
        });
    }

    @Override
    public void setNotifyData(List<PushMaterialOutput> pushMaterialOutputs) {
        materialAdapter.setNotifyData(pushMaterialOutputs);
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }

    @Override
    public void setPresenter(PushMaterialContract.Presenter presenter) {
        this.mPresenter = presenter;
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.onDestroyPresenter();
            mPresenter = null;
        }
    }
}
